package com.fenghuajueli.idiomppp.ui.fragment.story;


import android.os.Bundle;

import android.widget.ListView;

import com.fenghuajueli.idiomppp.R;
import com.fenghuajueli.idiomppp.adapter.ClassicStoryListAdapter;
import com.fenghuajueli.idiomppp.base.JumpActivityUtils;
import com.fenghuajueli.idiomppp.database.IdiomDaoUtils;
import com.fenghuajueli.idiomppp.entity.IdiomStoryEntity;
import com.fenghuajueli.idiomppp.ui.idiomstory.IdiomStoryActivity;
import com.fenghuajueli.idiomppp.utils.RuntimeDataUtils;
import com.fenghuajueli.libbasecoreui.listener.OnListClickListener;
import com.fenghuajueli.libbasecoreui.mvp.OtherBaseFragment;



/**
 * 成语故事列表
 */
public class IdiomStoryFragment extends OtherBaseFragment {

    ListView classicStoryListView;
    ClassicStoryListAdapter classicStoryListAdapter;

    @Override
    public void initView(Bundle savedInstanceState) {
        classicStoryListView = (ListView) findViewById(R.id.classicStoryListView);
        showLoadingDialog();
        classicStoryListAdapter = new ClassicStoryListAdapter(getActivity(), IdiomDaoUtils.getIdiomStoryManager().listAll());
        classicStoryListAdapter.setOnListClickListener(new OnListClickListener<IdiomStoryEntity>() {
            @Override
            public void itemClick(int position, IdiomStoryEntity data) {
                RuntimeDataUtils.idiomStoryEntity = data;
                JumpActivityUtils.goNormalActivity(getContext(), IdiomStoryActivity.class);
            }
        });
        classicStoryListAdapter.setShowAll(true);
        classicStoryListView.setAdapter(classicStoryListAdapter);
        hideLoadingDialog();

    }

    @Override
    public int getContentViewId() {
        return R.layout.fragment_idiom_story;
    }

    public static IdiomStoryFragment newInstance() {

        Bundle args = new Bundle();

        IdiomStoryFragment fragment = new IdiomStoryFragment();
        fragment.setArguments(args);
        return fragment;
    }

}
